import time

from appium.webdriver.common.appiumby import AppiumBy
from pages.base_page import BasePage



class LoginPage(BasePage):

    # 元素定位器
    USERNAME_INPUT = (AppiumBy.ID, 'com.topboya.linker:id/et_account')
    PASSWORD_INPUT = (AppiumBy.ID, 'com.topboya.linker:id/et_pw')
    HIDE_PWD=(AppiumBy.ID,'com.topboya.linker:id/cb_hide_pw')
    COMPANY_CODE=(AppiumBy.ID,'com.topboya.linker:id/tv_forget_pw')
    REMEBER_PASSWORD = (AppiumBy.ID, 'com.topboya.linker:id/cb_remember_pw')
    FORGET_PASSWORD=(AppiumBy.ID,'com.topboya.linker:id/tv_forget_pw')

    LOGIN_BUTTON = (AppiumBy.ID, 'com.topboya.linker:id/tv_login')
    ERROR_MESSAGE = (AppiumBy.ID, 'com.example.app:id/error_message')

    Agree_to_Privacy = (AppiumBy.ID, 'com.topboya.linker:id/cb_agree')
    Privacy = (AppiumBy.ID,'com.topboya.linker:id/tv_agreement2')



    def enter_username(self, username):
        self.send_keys(self.USERNAME_INPUT, username)

    def enter_password(self, password):
        self.send_keys(self.PASSWORD_INPUT, password)

    def click_remeber(self):
        self.click(self.REMEBER_PASSWORD)

    def click_Agree_to_Privacy(self):
        self.click(self.Agree_to_Privacy)

    def click_login(self):
        self.click(self.LOGIN_BUTTON)


    def get_error_message(self):
        return self.get_text(self.ERROR_MESSAGE)


    def login(self, username, password):
        self.enter_username(username)
        self.enter_password(password)
        self.click_remeber()
        self.click_Agree_to_Privacy()
        self.click_login()
        time.sleep(2)